package com.demo.springBootDemo07.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
import com.demo.springBootDemo07.entity.Dept;

@Configuration
public class AppConfig {

	//返回值注册为bean
	//入参从容器中取bean
	@Bean
	public RedisTemplate<String, Dept> deptRedisTemplate(RedisConnectionFactory connectionFactory) {
		RedisTemplate<String, Dept> redisTemplate = new RedisTemplate<String, Dept>();
		redisTemplate.setConnectionFactory(connectionFactory);
		//配置序列化实现类
		redisTemplate.setHashKeySerializer(new StringRedisSerializer());
		redisTemplate.setHashValueSerializer(new FastJsonRedisSerializer<Dept>(Dept.class));
		redisTemplate.setKeySerializer(new StringRedisSerializer());
		redisTemplate.setValueSerializer(new FastJsonRedisSerializer<Dept>(Dept.class));
		return redisTemplate;
	}

}
